home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / libsipp / sipp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-17  |  9.3 KB  |  324 lines

  1. /**
  2.  ** sipp - SImple Polygon Processor
  3.  **
  4.  **  A general 3d graphic package
  5.  **
  6.  **  Copyright Equivalent Software HB  1992
  7.  **
  8.  ** This program is free software; you can redistribute it and/or modify
  9.  ** it under the terms of the GNU General Public License as published by
  10.  ** the Free Software Foundation; either version 1, or any later version.
  11.  ** This program is distributed in the hope that it will be useful,
  12.  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  ** GNU General Public License for more details.
  15.  ** You can receive a copy of the GNU General Public License from the
  16.  ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  **/
  18.  
  19. /**
  20.  ** sipp.h - Public inteface to the sipp rendering library.
  21.  **/
  22.  
  23.  
  24. #ifndef _SIPP_H
  25. #define _SIPP_H
  26.  
  27. #include <geometric.h>
  28.  
  29.  
  30. #ifndef M_PI
  31. #define M_PI 3.1415926535897932384626
  32. #endif
  33.  
  34. #ifndef FALSE
  35. typedef int bool;
  36. #define FALSE  0
  37. #define TRUE   1
  38. #endif 
  39.  
  40. /*
  41.  * Customize for those that don't have memcpy() and friends, but
  42.  * have bcopy() instead.
  43.  */
  44.  
  45. #ifdef NOMEMCPY
  46. #define memcpy(to, from, n) bcopy((from), (to), (n))
  47. #endif
  48.  
  49.  
  50. /*
  51.  * The macro RANDOM() should return a random number
  52.  * in the range [-1, 1].
  53.  */
  54. #ifdef GO32
  55. #include <stdlib.h>
  56. #define RANDOM()  (random() / (MAXINT * 0.5) - 1.0)
  57. #else
  58. extern double drand48();
  59. #define RANDOM()  (2.0 * drand48() - 1.0)
  60. #endif
  61.  
  62.  
  63. /*
  64.  * Modes for rendering
  65.  */
  66. #define PHONG      0
  67. #define GOURAUD    1
  68. #define FLAT       2
  69. #define LINE       3
  70.  
  71.  
  72. /*
  73.  * Field definition.
  74.  */
  75. #define EVEN   0
  76. #define ODD    1
  77. #define BOTH   2
  78.  
  79.  
  80. /*
  81.  * Types of lightsources.
  82.  */
  83. #define LIGHT_DIRECTION    0
  84. #define LIGHT_POINT        1
  85.  
  86. /*
  87.  * Types of spotlights (actually lightsource types too).
  88.  */
  89. #define SPOT_SHARP   2
  90. #define SPOT_SOFT    3
  91.  
  92.  
  93. /*
  94.  * Interface to shader functions.
  95.  */
  96. typedef void Shader();
  97.  
  98.  
  99. /*
  100.  * Colors are handled as an rgb-triple
  101.  * with values between 0 and 1.
  102.  */
  103. typedef struct {
  104.     double   red;
  105.     double   grn;
  106.     double   blu;
  107. } Color;
  108.  
  109.  
  110. /*
  111.  * Structure storing the vertices in surfaces. The vertices for a
  112.  * surface are stored in a binary tree sorted first on x, then y and last z.
  113.  */
  114. typedef struct vertex_t {
  115.     Vector            pos;    /* vertex position */
  116.     Vector            normal;    /* average normal at vertex */
  117.     Vector            texture;    /* texture parameters (if any) */
  118.     struct vertex_t  *big, *sml;  /* pointers to children in the tree */
  119. } Vertex;
  120.  
  121.  
  122. /*
  123.  * Polygon definition. A polygon is defined by a list of
  124.  * references to its vertices (counterclockwize order).
  125.  */
  126. typedef struct polygon_t {
  127.     int         nvertices;
  128.     Vertex    **vertex;
  129.     bool        backface;   /* polygon is backfacing (used at rendering) */
  130.     struct polygon_t *next;
  131. } Polygon;
  132.  
  133.  
  134. /*
  135.  * Surface definition. Each surface consists of a vertex tree, 
  136.  * a polygon list, a pointer to a surface description and a pointer
  137.  * to a shader function.
  138.  */
  139. typedef struct surface_t {
  140.     Vertex           *vertices;          /* vertex tree */
  141.     Polygon          *polygons;          /* polygon list */
  142.     void             *surface;           /* surface description */
  143.     Shader           *shader;            /* shader function */
  144. /*    Vector            max, min;          / * Bounding box (Future use) */
  145.     int               ref_count;         /* no of references to this surface */
  146.     struct surface_t *next;              /* next surface in the list */
  147. } Surface;
  148.  
  149.  
  150. /*
  151.  * Object definition. Object consists of one or more
  152.  * surfaces and/or one or more subojects. Each object
  153.  * has its own transformation matrix that affects itself
  154.  * and all its subobjects.
  155.  */
  156. typedef struct object_t {
  157.     Surface         *surfaces;       /* List of surfaces */
  158.     struct object_t *sub_obj;        /* List of subobjects */
  159.     Transf_mat       transf;         /* Transformation matrix */
  160.     int              ref_count;      /* No of references to this object */
  161.     struct object_t *next;           /* Next object in this list */
  162. } Object;
  163.  
  164.  
  165.  
  166. /*
  167.  * Information needed in a lightsource to generate
  168.  * shadows.
  169.  */
  170. typedef struct {
  171.     Transf_mat  matrix;
  172.     double      fov_factor;
  173.     double      bias;
  174.     bool        active;
  175.     float      *d_map;
  176. } Shadow_info;
  177.  
  178.  
  179. /*
  180.  * Public part of lightsource definition.
  181.  * Used for both normal lightsources and spotlights.
  182.  */
  183. typedef struct lightsource_t {
  184.     Color                 color;      /* Color of the lightsource */
  185.     bool                  active;     /* Is the light on? */
  186.     int                   type;       /* Type of lightsource */
  187.     void                 *info;       /* Type dependent info */
  188.     Shadow_info           shadow;     /* Shadow information */
  189.     struct lightsource_t *next;       /* next lightsource in the list */
  190. } Lightsource;
  191.  
  192.  
  193. /*
  194.  * Virtual camera definition
  195.  */
  196. typedef struct {
  197.     Vector position;     /* camera position */
  198.     Vector lookat;       /* point to look at */
  199.     Vector up;           /* Up direction in the view */ 
  200.     double focal_ratio;
  201. } Camera;
  202.  
  203.  
  204. /*
  205.  * Surface description used by the basic shader. This shader
  206.  * does simple shading of surfaces of a single color.
  207.  */
  208. typedef struct {
  209.     double  ambient;       /* Fraction of color visible in ambient light */
  210.     double  specular;      /* Fraction of colour specularly reflected */
  211.     double  c3;            /* "Shinyness" 0 = shiny,  1 = dull */
  212.     Color   color;         /* Colour of the surface */
  213.     Color   opacity;       /* Opacity of the surface */
  214. } Surf_desc;
  215.  
  216.  
  217. extern char  * SIPP_VERSION;
  218.  
  219.  
  220. /*
  221.  * The world that is rendered. Defined in objects.c
  222.  */
  223. extern Object  *sipp_world;
  224.  
  225.  
  226. /*
  227.  * The internal (default) camera.
  228.  */
  229. extern Camera  *sipp_camera;
  230.  
  231.  
  232. /*
  233.  * This defines all public functions implemented in sipp.
  234.  */
  235.  
  236. /* Global initialization and configuration functions. */
  237. extern void          sipp_init();
  238. extern void          sipp_show_backfaces();
  239. extern void          sipp_shadows();
  240. extern void          sipp_background();
  241.  
  242. /* Functions for handling surfaces and objects. */
  243. extern void          vertex_push();
  244. extern void          vertex_tx_push();
  245. extern void          polygon_push();
  246. extern Surface      *surface_create();
  247. extern Surface      *surface_basic_create();
  248. extern void          surface_set_shader();
  249. extern void          surface_basic_shader();
  250. extern Object       *object_create();
  251. extern Object       *object_instance();
  252. extern Object       *object_dup();
  253. extern Object       *object_deep_dup();
  254. extern void          object_delete();
  255. extern void          object_add_surface();
  256. extern void          object_sub_surface();
  257. extern void          object_add_subobj();
  258. extern void          object_sub_subobj();
  259.  
  260. /* Functions for handling transforming objects. */
  261. extern void          object_set_transf();
  262. extern Transf_mat   *object_get_transf();
  263. extern void          object_clear_transf();
  264. extern void          object_transform();
  265. extern void          object_rot_x();
  266. extern void          object_rot_y();
  267. extern void          object_rot_z();
  268. extern void          object_rot();
  269. extern void          object_scale();
  270. extern void          object_move();
  271.  
  272. /* Functions for handling lightsources and spotlights. */
  273. extern Lightsource  *lightsource_create();
  274. extern Lightsource  *spotlight_create();
  275. extern void          light_destruct();
  276. extern void          lightsource_put();
  277. extern void          spotlight_pos();
  278. extern void          spotlight_at();
  279. extern void          spotlight_opening();
  280. extern void          spotlight_shadows();
  281. extern void          light_color();
  282. extern void          light_active();
  283. extern double        light_eval();
  284.  
  285. /* Functions for handling the viewpoint and virtual cameras. */
  286. extern Camera       *camera_create();
  287. extern void          camera_destruct();
  288. extern void          camera_pos();
  289. extern void          camera_at();
  290. extern void          camera_up();
  291. extern void          camera_focal();
  292. extern void          camera_params();
  293. extern void          camera_use();
  294.  
  295. /* Functions to render an image. */
  296. extern void          render_image_file();
  297. extern void          render_image_func();
  298. extern void          render_field_file();
  299. extern void          render_field_func();
  300.  
  301. /* The basic shader. */
  302. extern void          basic_shader();
  303.  
  304.  
  305. /*
  306.  * The following macros are provided for backward compatibility.
  307.  * We plan to remove them from future releases though,
  308.  * so we don't encourage use of them.
  309.  */
  310. #define object_install(obj)    object_add_subobj(sipp_world, obj);
  311. #define object_uninstall(obj)  object_sub_subobj(sipp_world, obj);
  312. #define view_from(x, y, z)     camera_position(sipp_camera, x, y, z)
  313. #define view_at(x, y, z)       camera_look_at(sipp_camera, x, y, z)
  314. #define view_up(x, y, z)       camera_up(sipp_camera, x, y, z)
  315. #define view_focal(fr)         camera_focal(sipp_camera, fr)
  316. #define viewpoint(x, y, z, x2, y2, z2, ux, uy, uz, fr)\
  317.     camera_params(sipp_camera, x, y, z, x2, y2, z2, ux, uy, uz, fr)
  318. #define lightsource_push(x, y, z, i) \
  319.     lightsource_create(x, y, z, i, i, i, LIGHT_DIRECTION)
  320. #define render_image_pixmap(w, h, p, f, m, o) \
  321.     render_image_func(w, h, f, p, m, o)
  322.  
  323. #endif /* _SIPP_H */
  324.